#include <NewSoftSerial.h>
#include <OLED.h>

const int buttonPin = 8;

// Rx pin, Tx pin, reset pin
OLED oled(2, 3, 4);

// 
boolean wasPressed = true;

void setup() {
  // 
  oled.init();

  // 
  oled.setBackgroundColour(OLED_BLACK);

  // 
  oled.clearScreen();

  // 
  oled.setPenSize(OLED_SOLID);
  oled.drawRectangle(3, 4, 85, 18, OLED_WHITE);
  oled.setPenSize(OLED_WIRE_FRAME);
  oled.drawRectangle(3, 4, 85, 18, OLED_RED);

  // 
  oled.drawStringAsText(1, 1, OLED_SMALL_SIZE_FONT, "Make:", OLED_RED);

  // Cyan
  unsigned int color = oled.get16bitColourFromRGB(0, 174, 239);
  oled.drawStringAsText(6, 1, OLED_SMALL_SIZE_FONT, "PROJECTS", color);
  oled.drawStringAsText(1, 3, OLED_SMALL_SIZE_FONT, "Prototyping", color);
  oled.drawStringAsText(1, 4, OLED_SMALL_SIZE_FONT, "Lab", color);

  // Magenta
  color = oled.get16bitColourFromRGB(236, 0, 140);
  oled.setPenSize(OLED_SOLID);
  oled.drawCircle(64, 64, 16, color);

  // Yellow
  color = oled.get16bitColourFromRGB(255, 212, 0);
  oled.drawTriangle(81, 80, 113, 80, 81, 48, color);
}

void loop() {
  // 
  boolean isPressed = (digitalRead(buttonPin) == HIGH);

  // 
  if (!wasPressed && isPressed) {
    // 
    oled.drawTextButton(
      OLED_BUTTON_DOWN, 0, 96, OLED_WHITE, OLED_SMALL_SIZE_FONT, 
      OLED_BLACK, 1, 1, "ON!");
  } 
  else if (wasPressed && !isPressed) {
    // 
    oled.drawTextButton(
      OLED_BUTTON_UP, 0, 96, OLED_WHITE, OLED_SMALL_SIZE_FONT, 
      OLED_BLACK, 1, 1, "OFF");
  }

  // 
  wasPressed = isPressed;

  // 
  char timeString[17];
  sprintf(timeString, "Time:%ld", millis());

  // 
  oled.setPenSize(OLED_SOLID);
  oled.drawRectangle(0, 120, 127, 127, OLED_BLACK);

  // 
  oled.drawStringAsText(1, 15, OLED_SMALL_SIZE_FONT, timeString, OLED_WHITE);

  // 
  delay(100);
}

